package com.webshop.database;



import com.mchange.v2.c3p0.*;
import com.webshop.domain.Items;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


public class ConnPool { static int max = 10;
    static Connection conn = null;
    static PreparedStatement ps = null;
    static ComboPooledDataSource dataSource = new ComboPooledDataSource();
    static String DriverClass = "com.mysql.cj.jdbc.Driver";
    static String JDBCurl = "jdbc:mysql://127.0.0.1:3306/webshop?useUnicode=true&characterEncoding=utf-8";
    static String user = "root";
    static String password = "root";

    static
    {
        try {
            dataSource.setDriverClass(DriverClass);
            dataSource.setJdbcUrl(JDBCurl);
            dataSource.setUser(user);
            dataSource.setPassword(password);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static Connection getConn(){
        try {
            conn = dataSource.getConnection();
            return conn;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
    public static void back(Connection c){
        conn = c;
        c = null;
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
